#include "StdAfx.h"
#include "DirectoryCam.h"
#include <highgui.h>
#include <list>


CDirectoryCam::CDirectoryCam(const char* directory)
{
    m_directory = directory;
    m_idx = -1;
}


CDirectoryCam::~CDirectoryCam(void)
{
}


void CDirectoryCam::Initialize()
{
    CFileFind fileFinder;
    CString targetDir = m_directory + "\\*.jpg";
    bool found = fileFinder.FindFile(targetDir);

    list<CString> files;
    while(found)
    {
        found = fileFinder.FindNextFile();
        m_files.push_back(fileFinder.GetFilePath());
    }

    files.sort();
    for (list<CString>::iterator it = files.begin(); it != files.end(); ++it)
    {
        m_files.push_back(*it);
    }

    m_initialized = true;
}

IplImage* CDirectoryCam::CaptureFrame()
{
    m_idx = ++m_idx % m_files.size();

    return cvLoadImage(m_files[m_idx]);
}
